<template>
  <u-modal :show="show" title="修改密码" showCancelButton @confirm="confirm" @cancel="cancel">
			<uni-forms ref="form" :model="formData" :rules="rules" labelWidth="80px">
				<uni-forms-item label="当前密码" required name="oldPassword">
					<uni-easyinput type="password" v-model="formData.oldPassword" placeholder="请输入当前密码" />
				</uni-forms-item>
				
				<uni-forms-item label="新的密码" required name="newPassword">
					<uni-easyinput type="password" v-model="formData.newPassword" placeholder="请输入新的密码" />
				</uni-forms-item>
				
				<uni-forms-item label="确认密码" required name="confirmPassword">
					<uni-easyinput type="password" v-model="formData.confirmPassword" placeholder="请输入确认密码" />
				</uni-forms-item>
			</uni-forms>
  </u-modal>
</template>

<script>
	import * as UserInfoApi from '@/api/user'
	export default {
		  props: {
		    show: Boolean
		  },
		data() {
			return {
				formData:{
					oldPassword:'',
					newPassword:'',
					confirmPassword:''
				},
				rules: {
					oldPassword: {
						rules: [{
							required: true,
							errorMessage: '当前密码不能为空'
						}]
					},
					newPassword: {
						rules: [{
							required: true,
							errorMessage: '新的密码不能为空'
						}]
					},
					confirmPassword: {
							rules: [{
								required: true,
								errorMessage: '确认密码为空'
							}]
						}
				},
			}
		},
	methods: {
		confirm () {
			this.$refs.form.validate().then(res => {
			    UserInfoApi.updateUserPwd(this.formData.oldPassword,this.formData.newPassword).then(res => {
			      uni.showToast({ title: '提交成功！' })
				  this.formData.oldPassword=''
				  this.formData.newPassword=''
				  this.formData.confirmPassword=''
				  this.$emit('close')
			    })
			});
		},
		cancel () {
			this.formData.oldPassword=''
			this.formData.newPassword=''
			this.formData.confirmPassword=''
		  this.$emit('close')
		},
		
	}
}
</script>

<style scoped>
</style>

